//
//  KDTestOperation.m
//  demo
//
//  Created by 叶青 on 15/9/11.
//  Copyright (c) 2015年 naruto. All rights reserved.
//

#import "KDTestOperation.h"

@implementation KDTestOperation
{
    BOOL        _p_executing;
    BOOL        _p_finished;
}
- (id)init
{
    self = [super init];
    if (self) {
        _p_executing = NO;
        _p_finished = NO;
    }
    return self;
}
-(void)dealloc
{
    NSLog(@"KDTestOperation dealloc");
}
-(void)start
{
    NSLog(@"KDTestOperation %@ start",self);
    _p_executing = YES;
    __weak typeof(self) weakSelf=self;
    dispatch_async(dispatch_get_main_queue(), ^{
        sleep(5);
        [weakSelf dotest];
    });
}

- (void)dotest
{
    [self willChangeValueForKey:@"isFinished"];
    _p_finished=YES;
    [self didChangeValueForKey:@"isFinished"];
    NSLog(@"KDTestOperation %@ end",self);
}
- (BOOL)isConcurrent
{
    return YES;
}

- (BOOL)isExecuting
{
    return _p_executing;
}

- (BOOL)isFinished
{
    return _p_finished;
}
@end
